/*    */ package client;
/*    */ 
/*    */ import com.alibaba.druid.pool.DruidPooledConnection;
/*    */ import java.io.Serializable;
/*    */ import java.sql.PreparedStatement;
/*    */ import java.sql.SQLException;
/*    */ import java.util.ArrayList;
/*    */ import java.util.Comparator;
/*    */ import java.util.List;
/*    */ import tools.Pair;
/*    */ import tools.data.output.MaplePacketLittleEndianWriter;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class MapleQuickSlot
/*    */   implements Serializable
/*    */ {
/*    */   private static final long serialVersionUID = 9179541993413738569L;
/*    */   private final List<Pair<Integer, Integer>> quickslot;
/*    */   private boolean changed = false;
/*    */   
/*    */   public MapleQuickSlot() {
/* 28 */     this.quickslot = new ArrayList<>();
/*    */   }
/*    */   
/*    */   public MapleQuickSlot(List<Pair<Integer, Integer>> quickslots) {
/* 32 */     this.quickslot = quickslots;
/*    */   }
/*    */   
/*    */   public List<Pair<Integer, Integer>> Layout() {
/* 36 */     this.changed = true;
/* 37 */     return this.quickslot;
/*    */   }
/*    */   
/*    */   public void unchanged() {
/* 41 */     this.changed = false;
/*    */   }
/*    */   
/*    */   public void resetQuickSlot() {
/* 45 */     this.changed = true;
/* 46 */     this.quickslot.clear();
/*    */   }
/*    */   
/*    */   public void addQuickSlot(int index, int key) {
/* 50 */     this.changed = true;
/* 51 */     this.quickslot.add(new Pair(Integer.valueOf(index), Integer.valueOf(key)));
/*    */   }
/*    */   
/*    */   public int getKeyByIndex(int index) {
/* 55 */     for (Pair<Integer, Integer> p : this.quickslot) {
/* 56 */       if (((Integer)p.getLeft()).intValue() == index) {
/* 57 */         return ((Integer)p.getRight()).intValue();
/*    */       }
/*    */     } 
/* 60 */     return -1;
/*    */   }
/*    */   
/*    */   public void writeData(MaplePacketLittleEndianWriter mplew) {
/* 64 */     mplew.write(this.quickslot.isEmpty() ? 0 : 1);
/* 65 */     if (this.quickslot.isEmpty()) {
/*    */       return;
/*    */     }
/* 68 */     this.quickslot.sort(Comparator.comparing(Pair::getLeft));
/* 69 */     for (Pair<Integer, Integer> qs : this.quickslot) {
/* 70 */       mplew.writeInt(((Integer)qs.getRight()).intValue());
/*    */     }
/*    */   }
/*    */   
/*    */   public void saveQuickSlots(DruidPooledConnection con, int charid) throws SQLException {
/* 75 */     if (!this.changed) {
/*    */       return;
/*    */     }
/* 78 */     try (PreparedStatement ps = con.prepareStatement("DELETE FROM quickslot WHERE characterid = ?")) {
/* 79 */       ps.setInt(1, charid);
/* 80 */       ps.execute();
/* 81 */       if (this.quickslot.isEmpty()) {
/*    */         return;
/*    */       }
/* 84 */       boolean first = true;
/* 85 */       StringBuilder query = new StringBuilder();
/* 86 */       for (Pair<Integer, Integer> q : this.quickslot) {
/* 87 */         if (first) {
/* 88 */           first = false;
/* 89 */           query.append("INSERT INTO quickslot VALUES (");
/*    */         } else {
/* 91 */           query.append(",(");
/*    */         } 
/* 93 */         query.append("DEFAULT,");
/* 94 */         query.append(charid).append(",");
/* 95 */         query.append(((Integer)q.getLeft()).intValue()).append(",");
/* 96 */         query.append(((Integer)q.getRight()).intValue()).append(")");
/*    */       } 
/* 98 */       try (PreparedStatement pse = con.prepareStatement(query.toString())) {
/* 99 */         pse.execute();
/*    */       } 
/*    */     } 
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\client\MapleQuickSlot.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */